<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2016/7/21
 * Time: 16:39
 */

namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller{
    public function login(){
        $this->display();
    }
    public function dologin(){
        $condition=array('adminname'=>$_POST['adminname'],
            'pass'=>md5(I('post.pass')));
        $adminModel=M('Admin');
        $admin=$adminModel->where($condition)->find();
        if($admin){
//            是合法用户 设置session
            session('admin',$admin);
            $this->redirect('Index/users');

        }else{
//            非法用户
            $this->error('用户名或口令错误！');
        }
    }

    public function loginout(){
        session('admin',null);
        $this->redirect('login');
    }
}